<!DOCTYPE html>
<html lang="en">

<!-- Head tag -->
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!--Description-->
    
        <meta name="description" content="本来想记录一下修复bug的过程,结果查了一堆资料,总结下Git的一些概念和使用方式">
    

    <!--Author-->
    
        <meta name="author" content="kobako">
    

    <!--Open Graph Title-->
    
        <meta property="og:title" content="git-submodule的使用以及bug"/>
    

    <!--Open Graph Description-->
    

    <!--Open Graph Site Name-->
    <meta property="og:site_name" content="Kobako"/>

    <!--Type page-->
    
        <meta property="og:type" content="article" />
    

    <!--Page Cover-->
    

    <meta name="twitter:card" content="summary" />
    

    <!-- Title -->
    
    <title>git-submodule的使用以及bug - Kobako</title>

    <!-- Bootstrap Core CSS -->
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css" integrity="sha384-y3tfxAZXuh4HwSYylfB+J125MxIs6mR5FOHamPBG064zB+AFeWH94NdvaCBm8qnd" crossorigin="anonymous">

    <!-- Custom Fonts -->
    <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" type="text/css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="//oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="//oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <!-- Gallery -->
    <link href="//cdnjs.cloudflare.com/ajax/libs/featherlight/1.3.5/featherlight.min.css" type="text/css" rel="stylesheet" />

    <!-- Custom CSS -->
    <link rel="stylesheet" href="/kobako-blog/css/style.css">

    <!-- Google Analytics -->
    


</head>


<body>

<div class="bg-gradient"></div>
<div class="bg-pattern"></div>

<!-- Menu -->
<!--Menu Links and Overlay-->
<div class="menu-bg">
    <div class="menu-container">
        <ul>
            
            <li class="menu-item">
                <a href="/kobako-blog/">
                    主页
                </a>
            </li>
            
            <li class="menu-item">
                <a href="/kobako-blog/archives">
                    历史文章
                </a>
            </li>
            
        </ul>
    </div>
</div>

<!--Hamburger Icon-->
<nav>
    <a href="#menu"></a>
</nav>

<div class="container">

    <!-- Main Content -->
    <div class="row">
    <div class="col-sm-12">

        <!--Title and Logo-->
        <header>
    <div class="logo">
        <a href="/kobako-blog/"><i class="logo-icon fa fa-apple" aria-hidden="true"></i></a>
        
    </div>
</header>

        <section class="main">
            
<div class="post">

    <div class="post-header">
        <h1 class="title">
            <a href="/kobako-blog/2018/06/13/git-submodule-bug/">
                git-submodule的使用以及bug
            </a>
        </h1>
        <div class="post-info">
            
                <span class="date">2018-06-13</span>
            
            
            
        </div>
    </div>

    <div class="content">

        <!-- Gallery -->
        

        <!-- Post Content -->
        <p>本来想记录一下修复bug的过程,结果查了一堆资料,总结下Git的一些概念和使用方式</p>
<a id="more"></a>
<p>在使用submodule来管理引用项目的时候,报未知路径的错误,这个路径是已经被弃用了的,说明缓存里面有问题</p>
<h3 id="未知路径解决方法"><a href="#未知路径解决方法" class="headerlink" title="未知路径解决方法"></a>未知路径解决方法</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ git rm --cached yourpath -r</span><br></pre></td></tr></table></figure>
<h3 id="Add"><a href="#Add" class="headerlink" title="Add"></a>Add</h3><p>使用 git submodule add <code>&lt;repository&gt;</code> <code>&lt;path&gt;</code> 来增加一个submodule</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">$ git submodule add https://github.com/chaconinc/DbConnector</span><br><span class="line">Cloning into <span class="string">'DbConnector'</span>...</span><br><span class="line">remote: Counting objects: 11, <span class="keyword">done</span>.</span><br><span class="line">remote: Compressing objects: 100% (10/10), <span class="keyword">done</span>.</span><br><span class="line">remote: Total 11 (delta 0), reused 11 (delta 0)</span><br><span class="line">Unpacking objects: 100% (11/11), <span class="keyword">done</span>.</span><br><span class="line">Checking connectivity... <span class="keyword">done</span>.</span><br></pre></td></tr></table></figure>
<p>这个时候使用git status:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">$ git status</span><br><span class="line">On branch master</span><br><span class="line">Your branch is up-to-date with <span class="string">'origin/master'</span>.</span><br><span class="line"></span><br><span class="line">Changes to be committed:</span><br><span class="line">  (use <span class="string">"git reset HEAD &lt;file&gt;..."</span> to unstage)</span><br><span class="line"></span><br><span class="line">	new file:   .gitmodules</span><br><span class="line">	new file:   DbConnector</span><br></pre></td></tr></table></figure>
<h3 id="题外-git-diff-的用法"><a href="#题外-git-diff-的用法" class="headerlink" title="题外: git diff 的用法"></a>题外: git diff 的用法</h3><p><a href="https://veerasundar.com/blog/2011/06/git-tutorial-comparing-files-with-diff/" target="_blank" rel="noopener">Git tutorial – comparing files with diff
</a></p>
<p>讲到三个概念: <code>local repository</code>,<code>working directory</code>,<code>index</code>,虽然不是很明白,先记一下</p>
<p>注: working tree -add-&gt; index -commit-&gt; local repository</p>
<p>改: 下面的操作是从git help里面获得的,比博客的要更准确,所以替换掉了</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">$ git diff            (1)</span><br><span class="line">$ git diff --cached   (2)</span><br><span class="line">$ git diff HEAD       (3)</span><br></pre></td></tr></table></figure>
<ol>
<li>Changes in the working tree not yet staged for the next commit.</li>
<li>Changes between the index and your last commit; what you would be committing if you run “git commit” without “-a” option.</li>
<li>Changes in the working tree since your last commit; what you would be committing if you run “git commit -a”</li>
</ol>
<p>想对比两个不同分支之间某个文件的差异,用这个语句</p>
<p><code>git diff &lt;commit-id1&gt; &lt;commit-id2&gt; &lt;file_list&gt;</code></p>
<h4 id="diff更好的解释"><a href="#diff更好的解释" class="headerlink" title="diff更好的解释"></a>diff更好的解释</h4><p><img src="https://i.stack.imgur.com/tVHYO.png" alt="更好的解释"></p>
<h5 id="git-diff"><a href="#git-diff" class="headerlink" title="git diff"></a>git diff</h5><p>Shows the changes between the working directory and the index. This shows what has been changed, but is not staged for a commit.</p>
<h5 id="git-diff-–cached"><a href="#git-diff-–cached" class="headerlink" title="git diff –cached"></a>git diff –cached</h5><p>Shows the changes between the index and the HEAD (which is the last commit on this branch). This shows what has been added to the index and staged for a commit.</p>
<h5 id="git-diff-HEAD"><a href="#git-diff-HEAD" class="headerlink" title="git diff HEAD"></a>git diff HEAD</h5><p>Shows all the changes between the working directory and HEAD (which includes changes in the index). This shows all the changes since the last commit, whether or not they have been staged for commit or not.</p>
<h3 id="使用init和update初始化submodule"><a href="#使用init和update初始化submodule" class="headerlink" title="使用init和update初始化submodule"></a>使用init和update初始化submodule</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">$ git submodule init</span><br><span class="line">Submodule <span class="string">'DbConnector'</span> (https://github.com/chaconinc/DbConnector) registered <span class="keyword">for</span> path <span class="string">'DbConnector'</span></span><br><span class="line">$ git submodule update</span><br><span class="line">Cloning into <span class="string">'DbConnector'</span>...</span><br><span class="line">remote: Counting objects: 11, <span class="keyword">done</span>.</span><br><span class="line">remote: Compressing objects: 100% (10/10), <span class="keyword">done</span>.</span><br><span class="line">remote: Total 11 (delta 0), reused 11 (delta 0)</span><br><span class="line">Unpacking objects: 100% (11/11), <span class="keyword">done</span>.</span><br><span class="line">Checking connectivity... <span class="keyword">done</span>.</span><br><span class="line">Submodule path <span class="string">'DbConnector'</span>: checked out <span class="string">'c3f01dc8862123d317dd46284b05b6892c7b29bc'</span></span><br></pre></td></tr></table></figure>
<h3 id="题外-Git-工作流"><a href="#题外-Git-工作流" class="headerlink" title="题外: Git 工作流"></a>题外: Git 工作流</h3><p><img src="https://i.stack.imgur.com/caci5.png" alt="GIt工作流"></p>
<ol>
<li>the workspace is the directory tree of (source) files that you see and edit.</li>
<li>The index is a single, large, binary file in <code>&lt;baseOfRepo&gt;/.git/index</code>, which lists all files in the current branch, their sha1 checksums, time stamps and the file name – it is not another directory with a copy of files in it.</li>
</ol>
<p>也就是说index保存的是更改</p>
<ol start="3">
<li>The local repository is a hidden directory (.git) including an objects directory containing all versions of every file in the repo (local branches and copies of remote branches) as a compressed “blob” file.</li>
</ol>
<p>local repository == <code>.git</code>目录,保存所有文件所有版本的信息</p>
<h3 id="题外-checkout-工作流"><a href="#题外-checkout-工作流" class="headerlink" title="题外: checkout 工作流"></a>题外: checkout 工作流</h3><p>这张图可以更好理解分支</p>
<p><img src="https://i.stack.imgur.com/6dUTQ.png" alt="工作流2"></p>

    </div>

    

    

    <!-- Comments -->
    

</div>
        </section>

    </div>
</div>


</div>

<!-- Footer -->
<div class="push"></div>

<footer class="footer-content">
    <div class="container">
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 footer-about">
                <h2>关于</h2>
                <p>
                    将就用来写一下技术博客
                </p>
            </div>
            
    <div class="col-xs-6 col-sm-6 col-md-3 col-lg-3 recent-posts">
        <h2>最近文章</h2>
        <ul>
            
            <li>
                <a class="footer-post" href="/kobako-blog/2018/06/14/elm-route-learn/">elm路由学习</a>
            </li>
            
            <li>
                <a class="footer-post" href="/kobako-blog/2018/06/13/git-submodule-bug/">git-submodule的使用以及bug</a>
            </li>
            
            <li>
                <a class="footer-post" href="/kobako-blog/2018/06/12/english-learn-note/">学习英语笔记</a>
            </li>
            
            <li>
                <a class="footer-post" href="/kobako-blog/2018/06/08/express-project-structure-design/">软工项目总结,Express项目架构实践</a>
            </li>
            
        </ul>
    </div>



            
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                <ul class="list-inline footer-social-icons">
                    
                    <li class="list-inline-item">
                        <a href="https://github.com/zhuobinggang">
                            <span class="footer-icon-container">
                                <i class="fa fa-github"></i>
                            </span>
                        </a>
                    </li>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    <li class="list-inline-item">
                        <a href="mailto:zhuobinggang@gmail.com">
                            <span class="footer-icon-container">
                                <i class="fa fa-envelope-o"></i>
                            </span>
                        </a>
                    </li>
                    
                    
                </ul>
            </div>
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                <div class="footer-copyright">
                    @kobako All right reserved
                </div>
            </div>
        </div>
    </div>
</footer>

<!-- After footer scripts -->

<!-- jQuery -->
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>

<!-- Tween Max -->
<script src="//cdnjs.cloudflare.com/ajax/libs/gsap/1.18.5/TweenMax.min.js"></script>

<!-- Gallery -->
<script src="//cdnjs.cloudflare.com/ajax/libs/featherlight/1.3.5/featherlight.min.js" type="text/javascript" charset="utf-8"></script>

<!-- Custom JavaScript -->
<script src="/kobako-blog/js/main.js"></script>

<!-- Disqus Comments -->



</body>

</html>